﻿//判断权限
function ajaxChkPower(_power){
	$.ajax({
		type:		"get",
		dataType:	"json",
		data:		"power=" + _power + "&time="+(new Date().getTime()),
		url:		site.Dir + "admin/otherpage/ajax.aspx?oper=chkadminpower",
		error:		function(XmlHttpRequest,textStatus, errorThrown) { alert(XmlHttpRequest.responseText);},
		success:	function(data){
			if(data.result == "1")
			{
				$(".adminbar").show();
			}
			else
			{
				$(".adminbar").hide();
			}
		}
	});
}

var gSubmitTimes = 0;
function oLogin()
{
	$.ajax({
		type:		"get",
		dataType:	"json",
		data:		"time="+(new Date().getTime()),
		url:		site.Dir + "ajax/user.aspx?oper=ajaxUserInfo",
		error:		function(XmlHttpRequest,textStatus, errorThrown){if(XmlHttpRequest.responseText!=""){alert(XmlHttpRequest.responseText);}},
		success:	function(data){
			if(data.adminid == "0")
			{
				alert("你还没登录或你不是管理员,请先登录");
				window.location.href=site.Dir;
			}
			else
			{
				var oDialog = new jcms$$Dialog('1', '管理登录', 350, 190, 'login', false);
				oDialog.init();
				var sHtml = '<form id="loginform"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">\
						<tr><td height="30" align="left">用户：<input name="txtAdminName" type="text" maxlength="16" id="txtAdminName" class="ipt" style="width:158px;" /></td></tr>\
						<tr><td height="30" align="left">密码：<input name="txtAdminPass" type="password" maxlength="16" id="txtAdminPass" class="ipt" style="width:158px;" /></td></tr>\
						<tr><td height="30" align="left">验证：<input name="txtAdminCode" type="text" maxlength="6" id="txtAdminCode" class="ipt" style="width:50px;ime-mode:disabled;" onpaste="return false"  /> <img onclick="this.src=jcms$$SetUrlRefresh(\''+site.Dir+'plus/getcode3.aspx'+'\');" src="'+site.Dir+'plus/getcode3.aspx?t='+(new Date().getTime())+'" align="absmiddle" style="cursor: pointer" alt="不区分大小写,点击换一张" title="不区分大小写,点击换一张" /><img id="imgRead" src="'+site.Dir+'publicstyle/maintb.gif" align="absmiddle" style="cursor: pointer" alt="收听验证码" title="收听验证码" onclick="PlayCodeVoice();" />\
						<span id="player"></span></td></tr>\
						<tr><td height="40" align="left">\
								<input id="rbt1" type="radio" name="LoginType" value="0" checked="checked" />安全登录\
								<input id="rbt2" type="radio" name="LoginType" value="7" />记住密码&nbsp;&nbsp;&nbsp;\
								<input type="button" name="btnLogin" value="登录" onclick="javascript:chkLogin();" id="btnLogin" class="btn" />\
							</td></tr>\
					</table></form>\
				';
				oDialog.event(sHtml,'');
				$("#txtAdminName").val('');
				$("#txtAdminPass").val('');
				$("#txtAdminName").focus();
			}
		}
	});
}
function chkLogin(){
	if(gSubmitTimes>2){
		alert('请想想密码再来');
		return;
	}
	var uName="";
	var uPass="";
	var uCode="";
	uName=$("#txtAdminName").val();
	uPass=$("#txtAdminPass").val();
	uCode=$("#txtAdminCode").val();
	if(uName==""){
		alert('请填写用户名');
		$("#txtAdminName").focus();
		return;
	}
	if(uPass==""){
		alert('请填写密码');
		$("#txtAdminPass").focus();
		return;
	}
	if(uCode != ReadCookie("ValidateCode")){
		alert('验证码错误');
		$("#txtAdminCode").focus();
		return;
	}
	var typeNum;
	var rbType=$("#loginform input");
	for(var i=0;i<rbType.length;i++)
	{
		if(rbType[i].checked && rbType[i].type=="radio" && rbType[i].name=="LoginType"){
			typeNum=rbType[i].value;
		}
	}
	$.ajax({
		type:		"post",
		dataType:	"html",
		url:		site.Dir + "admin/otherpage/ajax.aspx?oper=login&time="+(new Date().getTime()),
		data:		"name="+uName+"&pass="+escape(uPass)+"&code="+escape(uCode)+"&type="+typeNum,
        		error:		function(XmlHttpRequest,textStatus, errorThrown) { alert(XmlHttpRequest.responseText);},
		success:	function(d){
            if (d== "ok")
				top.location.href=site.Dir + 'admin/index.htm';
			else
			{
				gSubmitTimes=gSubmitTimes+1;
				alert(d);
			}
		}
	});
}
function chkLogout(){
	$.ajax({
		type:		"get",
		dataType:	"json",
		url:		site.Dir + "admin/otherpage/ajax.aspx?oper=logout&time="+(new Date().getTime()),
        	error:		function(XmlHttpRequest,textStatus, errorThrown) { alert(XmlHttpRequest.responseText);},
		success:	function(d){
			if(d.result=="1")
				top.location.href=site.Dir + 'admin/login.htm';
		}
	});
}

function sendRequest(p){
	if(p==0)
	{
		oLogin();
		return;
	}
	$.ajax({
		url:		site.Dir + "admin/otherpage/ajax.aspx?time="+(new Date().getTime()),
		type:		"get",
		dataType:	"json",
		error:		function(XmlHttpRequest,textStatus, errorThrown) { alert(XmlHttpRequest.responseText);},
		success:	function(d){
			if(d.result=="1")
				top.location.href=site.Dir + 'admin/index.htm';
			else
				oLogin();
		}
	});
}
function ajaxClearCache()
{
	top.JumbotCms.Loading.show("正在更新，请等待...");
	$.ajax({
		type:		"get",
		dataType:	"json",
		data:		"oper=ajaxClearCache",
		url:		site.Dir + "admin/otherpage/ajax.aspx?time="+(new Date().getTime()),
		error:		function(XmlHttpRequest,textStatus, errorThrown){top.JumbotCms.Loading.hide();alert(XmlHttpRequest.responseText); },
		success:	function(d){
			switch (d.result)
			{
			case '-1':
				top.JumbotCms.Alert(d.returnval, "0", "top.window.location='" + site.Dir + "admin/login.htm';");
				break;
			case '0':
				top.JumbotCms.Alert(d.returnval, "0");
				break;
			case '1':
				top.JumbotCms.Loading.hide();
				top.JumbotCms.Alert(d.returnval, "1");
				break;
			}
		}
	});
}
function ajaxCreateCopyright()
{
	top.JumbotCms.Loading.show("正在更新，请等待...");
	ajaxCopyright("temporarydiv", "js");
	ajaxCopyright("temporarydiv", "html");
	top.JumbotCms.Alert("更新完成", "1");
}
function ajaxCreateSystemTree()
{
	top.JumbotCms.Loading.show("正在更新，请等待...");
	$.ajax({
		type:		"get",
		dataType:	"json",
		data:		"oper=ajaxCreateSystemTree",
		url:		site.Dir + "admin/otherpage/ajax.aspx?time="+(new Date().getTime()),
		error:		function(XmlHttpRequest,textStatus, errorThrown){top.JumbotCms.Loading.hide();alert(XmlHttpRequest.responseText); },
		success:	function(d){
			switch (d.result)
			{
			case '-1':
				top.JumbotCms.Alert(d.returnval, "0", "top.window.location='" + site.Dir + "admin/login.htm';");
				break;
			case '0':
				top.JumbotCms.Alert(d.returnval, "0");
				break;
			case '1':
				top.JumbotCms.Alert(d.returnval, "1");
				break;
			}
		}
	});
}
function ajaxCreateSystemCount()
{
	top.JumbotCms.Loading.show("正在更新，时间可能会比较长...");
	$.ajax({
		type:		"get",
		dataType:	"json",
		data:		"oper=ajaxCreateSystemCount",
		url:		site.Dir + "admin/otherpage/ajax.aspx?time="+(new Date().getTime()),
		error:		function(XmlHttpRequest,textStatus, errorThrown){top.JumbotCms.Loading.hide();alert(XmlHttpRequest.responseText); },
		success:	function(d){
			switch (d.result)
			{
			case '-1':
				top.JumbotCms.Alert(d.returnval, "0", "top.window.location='" + site.Dir + "admin/login.htm';");
				break;
			case '0':
				top.JumbotCms.Alert(d.returnval, "0");
				break;
			case '1':
				top.JumbotCms.Alert(d.returnval, "1");
				break;
			}
		}
	});
}
function ajaxCreateTopNav()
{
	top.JumbotCms.Loading.show("正在更新，请等待...");
	ajaxPluginTopNav("temporarydiv", "js");
	ajaxPluginTopNav("temporarydiv", "html");
	top.JumbotCms.Loading.hide();
	top.JumbotCms.Alert("更新成功", "1");
}
function ajaxCreateRssMapNav()
{
	top.JumbotCms.Loading.show("正在更新，请等待...");
	ajaxPluginRssMap("temporarydiv", "js");
	ajaxPluginRssMap("temporarydiv", "html");
	top.JumbotCms.Loading.hide();
	top.JumbotCms.Alert("更新成功", "1");
}
function ajaxCreateSiteMapNav()
{
	top.JumbotCms.Loading.show("正在更新，请等待...");
	ajaxPluginSiteMap("temporarydiv", "js");
	ajaxPluginSiteMap("temporarydiv", "html");
	top.JumbotCms.Loading.hide();
	top.JumbotCms.Alert("更新成功", "1");
}
function ajaxCreateIndexPage()
{
	top.JumbotCms.Loading.show("正在更新，请等待...");
	$.ajax({
		type:		"get",
		dataType:	"json",
		data:		"oper=ajaxCreateIndexPage",
		url:		site.Dir + "admin/otherpage/ajax.aspx?time="+(new Date().getTime()),
		error:		function(XmlHttpRequest,textStatus, errorThrown){top.JumbotCms.Loading.hide();alert(XmlHttpRequest.responseText); },
		success:	function(d){
			switch (d.result)
			{
			case '-1':
				top.JumbotCms.Alert(d.returnval, "0", "top.window.location='" + site.Dir + "admin/login.htm';");
				break;
			case '0':
				top.JumbotCms.Alert(d.returnval, "0");
				break;
			case '1':
				top.JumbotCms.Alert(d.returnval, "1");
				break;
			}
		}
	});
}
function ajaxCreateGlobalCSS()
{
	top.JumbotCms.Loading.show("正在更新，请等待...");
	$.ajax({
		type:		"get",
		dataType:	"json",
		data:		"oper=ajaxCreateGlobalCSS",
		url:		site.Dir + "admin/skins/ajax.aspx?time="+(new Date().getTime()),
		error:		function(XmlHttpRequest,textStatus, errorThrown){top.JumbotCms.Loading.hide();alert(XmlHttpRequest.responseText); },
		success:	function(d){
			switch (d.result)
			{
			case '-1':
				top.JumbotCms.Alert(d.returnval, "0", "top.window.location='" + site.Dir + "admin/login.htm';");
				break;
			case '0':
				top.JumbotCms.Alert(d.returnval, "0");
				break;
			case '1':
				top.JumbotCms.Alert(d.returnval, "1");
				break;
			}
		}
	});
}
function ajaxCreateContentLi()
{
	top.JumbotCms.Loading.show("正在更新，请等待...");
	$.ajax({
		type:		"get",
		dataType:	"json",
		data:		"oper=ajaxCreateContentLi",
		url:		site.Dir + "admin/templatecontentli/ajax.aspx?time="+(new Date().getTime()),
		error:		function(XmlHttpRequest,textStatus, errorThrown){top.JumbotCms.Loading.hide();alert(XmlHttpRequest.responseText); },
		success:	function(d){
			switch (d.result)
			{
			case '-1':
				top.JumbotCms.Alert(d.returnval, "0", "top.window.location='" + site.Dir + "admin/login.htm';");
				break;
			case '0':
				top.JumbotCms.Alert(d.returnval, "0");
				break;
			case '1':
				top.JumbotCms.Alert(d.returnval, "1");
				break;
			}
		}
	});
}
function ajaxCreateJavascript()
{
	top.JumbotCms.Loading.show("正在更新，请等待...");
	$.ajax({
		type:		"get",
		dataType:	"json",
		data:		"oper=ajaxCreateJavascript",
		url:		site.Dir + "admin/javascript/ajax.aspx?time="+(new Date().getTime()),
		error:		function(XmlHttpRequest,textStatus, errorThrown){top.JumbotCms.Loading.hide();alert(XmlHttpRequest.responseText); },
		success:	function(d){
			switch (d.result)
			{
			case '-1':
				top.JumbotCms.Alert(d.returnval, "0", "top.window.location='" + site.Dir + "admin/login.htm';");
				break;
			case '0':
				top.JumbotCms.Alert(d.returnval, "0");
				break;
			case '1':
				top.JumbotCms.Alert(d.returnval, "1");
				break;
			}
		}
	});
}
function ajaxCreatePluginFile()
{
	top.JumbotCms.Loading.show("正在更新，请等待...");
	$.ajax({
		type:		"get",
		dataType:	"json",
		data:		"oper=ajaxCreatePluginFile",
		url:		site.Dir + "admin/extends/ajax.aspx?time="+(new Date().getTime()),
		error:		function(XmlHttpRequest,textStatus, errorThrown){top.JumbotCms.Loading.hide();alert(XmlHttpRequest.responseText); },
		success:	function(d){
			switch (d.result)
			{
			case '-1':
				top.JumbotCms.Alert(d.returnval, "0", "top.window.location='" + site.Dir + "admin/login.htm';");
				break;
			case '0':
				top.JumbotCms.Alert(d.returnval, "0");
				break;
			case '1':
				top.JumbotCms.Alert(d.returnval, "1");
				break;
			}
		}
	});
}
function ajaxCreateRssMap()
{
	top.JumbotCms.Loading.show("正在更新，请等待...");
	$.ajax({
		type:		"get",
		dataType:	"json",
		data:		"oper=ajaxCreateRssMap",
		url:		site.Dir + "admin/otherpage/ajax.aspx?time="+(new Date().getTime()),
		error:		function(XmlHttpRequest,textStatus, errorThrown){top.JumbotCms.Loading.hide();alert(XmlHttpRequest.responseText); },
		success:	function(d){
			switch (d.result)
			{
			case '-1':
				top.JumbotCms.Alert(d.returnval, "0", "top.window.location='" + site.Dir + "admin/login.htm';");
				break;
			case '0':
				top.JumbotCms.Alert(d.returnval, "0");
				break;
			case '1':
				top.JumbotCms.Alert(d.returnval, "1");
				break;
			}
		}
	});
}
function ajaxCreateSiteMap()
{
	top.JumbotCms.Loading.show("正在更新，请等待...");
	$.ajax({
		type:		"get",
		dataType:	"json",
		data:		"oper=ajaxCreateSiteMap",
		url:		site.Dir + "admin/otherpage/ajax.aspx?time="+(new Date().getTime()),
		error:		function(XmlHttpRequest,textStatus, errorThrown){top.JumbotCms.Loading.hide();alert(XmlHttpRequest.responseText); },
		success:	function(d){
			switch (d.result)
			{
			case '-1':
				top.JumbotCms.Alert(d.returnval, "0", "top.window.location='" + site.Dir + "admin/login.htm';");
				break;
			case '0':
				top.JumbotCms.Alert(d.returnval, "0");
				break;
			case '1':
				top.JumbotCms.Alert(d.returnval, "1");
				break;
			}
		}
	});
}
function ajaxModuleUpdateFore()
{
	top.JumbotCms.Loading.show("正在更新，请等待...");
	$.ajax({
		type:		"get",
		dataType:	"json",
		data:		"time="+(new Date().getTime()),
		url:		site.Dir + "admin/modules/ajax.aspx?oper=updatefore",
		error:		function(XmlHttpRequest,textStatus, errorThrown){top.JumbotCms.Loading.hide();alert(XmlHttpRequest.responseText); },
		success:	function(d){
			switch (d.result)
			{
			case '-1':
				top.JumbotCms.Alert(d.returnval, "0", "top.window.location='" + site.Dir + "admin/login.htm';");
				break;
			case '0':
				top.JumbotCms.Alert(d.returnval, "0");
				break;
			case '1':
				top.JumbotCms.Alert(d.returnval, "1");
				break;
			}
		}
	});
}
